<?php
/**
 * 检查ThinkAdmin节点扫描情况
 */

// 引入框架
require_once __DIR__ . '/../../vendor/autoload.php';

// 设置正确的根路径
$rootPath = dirname(__DIR__, 2);
chdir($rootPath);

try {
    // 初始化应用
    $app = new \think\App($rootPath);
    $app->initialize();
    
    echo "=== 检查ThinkAdmin节点扫描 ===\n\n";
    
    // 获取所有节点
    $nodes = \think\admin\service\NodeService::getMethods(true);
    
    echo "总共扫描到 " . count($nodes) . " 个节点\n\n";
    
    // 查找checkin相关的节点
    $checkinNodes = [];
    foreach ($nodes as $node => $info) {
        if (strpos($node, 'checkin/') === 0) {
            $checkinNodes[$node] = $info;
        }
    }
    
    echo "Checkin模块节点 (" . count($checkinNodes) . " 个):\n";
    foreach ($checkinNodes as $node => $info) {
        $auth = $info['isauth'] ? '需要权限' : '无需权限';
        $menu = $info['ismenu'] ? '可作菜单' : '不可菜单';
        echo "  {$node} - {$info['title']} ({$auth}, {$menu})\n";
    }
    
    // 特别检查device相关节点
    echo "\nDevice控制器节点:\n";
    $deviceNodes = [];
    foreach ($checkinNodes as $node => $info) {
        if (strpos($node, 'checkin/device/') === 0) {
            $deviceNodes[$node] = $info;
            $auth = $info['isauth'] ? '需要权限' : '无需权限';
            $menu = $info['ismenu'] ? '可作菜单' : '不可菜单';
            echo "  ✓ {$node} - {$info['title']} ({$auth}, {$menu})\n";
        }
    }
    
    if (empty($deviceNodes)) {
        echo "  ❌ 没有找到device控制器节点！\n";
        echo "  请检查控制器文件是否存在，注解是否正确。\n";
    }
    
    // 检查菜单节点
    echo "\n可作为菜单的节点:\n";
    $menuNodes = \think\admin\service\MenuService::getList(true);
    $checkinMenuNodes = [];
    foreach ($menuNodes as $menuNode) {
        if (strpos($menuNode['node'], 'checkin/') === 0) {
            $checkinMenuNodes[] = $menuNode;
            echo "  ✓ {$menuNode['node']} - {$menuNode['title']}\n";
        }
    }
    
    if (empty($checkinMenuNodes)) {
        echo "  ❌ 没有找到checkin模块的菜单节点！\n";
    }
    
    echo "\n=== 检查完成 ===\n";
    
} catch (\Throwable $e) {
    echo "错误: " . $e->getMessage() . "\n";
    echo "堆栈: " . $e->getTraceAsString() . "\n";
}
?>
